package com.dotndot.momserver.data;

import java.util.*;

import javax.jdo.annotations.*;
import com.dotndot.momserver.data.Sleep;
import com.dotndot.momserver.data.Nappy;
import com.dotndot.momserver.data.Food;
import com.dotndot.momserver.data.Hospital;

@PersistenceCapable( identityType = IdentityType.APPLICATION )
public class Diary
{
    public static final int CATEGORY_SLEEP = 0;
    public static final int CATEGORY_NAPPY = 1;
    public static final int CATEGORY_FOOD = 2;
    public static final int CATEGORY_HOSPITAL = 3;
    
    @PrimaryKey
    @Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
    private Long index;

    @Persistent
    private Long babyIndex;

    @Persistent
    private int category;
    
    @Persistent
    private Date date;
    
    @Persistent
    private Sleep sleep;
    
    @Persistent
    private Nappy nappy;
    
    @Persistent
    private Food food;
    
    @Persistent
    private Hospital hospital;
        
    public Diary( Long babyIndex, int category, Date date, Object item){
        setBabyIndex(babyIndex);
        setCategory(category);
        setDate(date);
        
        switch(category){
            case CATEGORY_SLEEP:
                if(item instanceof Sleep){
                    setSleep((Sleep) item);
                }
                break;
            case CATEGORY_NAPPY:
                if(item instanceof Nappy){
                    setNappy((Nappy) item);
                }
                break;
            case CATEGORY_FOOD:
                if(item instanceof Food){
                    setFood((Food) item);
                }
                break;
            case CATEGORY_HOSPITAL:
                if(item instanceof Hospital){
                    setHospital((Hospital) item);
                }
                break;
        }
    }

    public Long getIndex()
    {
        return index;
    }

    public void setIndex( Long index )
    {
        this.index = index;
    }

    public Long getBabyIndex()
    {
        return babyIndex;
    }

    public void setBabyIndex( Long babyIndex )
    {
        this.babyIndex = babyIndex;
    }

    public int getCategory()
    {
        return category;
    }

    public void setCategory( int category )
    {
        this.category = category;
    }

    public Date getDate()
    {
        return date;
    }

    public void setDate( Date date )
    {
        this.date = date;
    }

    public Sleep getSleep()
    {
        return sleep;
    }

    public void setSleep( Sleep sleep )
    {
        this.sleep = sleep;
    }

    public Nappy getNappy()
    {
        return nappy;
    }

    public void setNappy( Nappy nappy )
    {
        this.nappy = nappy;
    }

    public Food getFood()
    {
        return food;
    }

    public void setFood( Food food )
    {
        this.food = food;
    }

    public Hospital getHospital()
    {
        return hospital;
    }

    public void setHospital( Hospital hospital )
    {
        this.hospital = hospital;
    }
    
    public Object getItem(){
        Object object = null;
        switch(category){
            case CATEGORY_SLEEP:
                object = sleep;
                break;
            case CATEGORY_NAPPY:
                object = nappy;
                break;
            case CATEGORY_FOOD:
                object = food;
                break;
            case CATEGORY_HOSPITAL:
                object = hospital;
                break;
        }
        return object;
    } 
}
